# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: leon

from coin.exchange.base.kr_rest.currency import NativeCurrency
from coin.exchange.quoinex_v2.kr_rest.constants import (quote_currency_list, base_currency_list)

currency_list = quote_currency_list + base_currency_list


def from_native_currency(native_currency):
  assert type(native_currency) is str
  assert native_currency.upper() == native_currency, native_currency
  assert native_currency in currency_list, native_currency
  currency = native_currency
  return currency


def to_native_currency(currency):
  assert type(currency) is str
  native_currency = currency
  assert native_currency in currency_list, currency
  return native_currency


class QuoinexCurrency(NativeCurrency):
  _exchange = 'Quoinex'

  def __init__(self, currency, native_currency):
    assert native_currency in currency_list, (currency, native_currency)
    assert native_currency.upper() == native_currency, (currency, native_currency)
    assert to_native_currency(currency) == native_currency, (currency, native_currency)
    super().__init__(currency, native_currency)

  @classmethod
  def FromStrCurrencyImpl(cls, currency_str, current_datetime):
    return cls(currency_str, to_native_currency(currency_str))

  @classmethod
  def FromStrNativeCurrencyImpl(cls, native_currency_str, current_datetime):
    return cls(from_native_currency(native_currency_str), native_currency_str)
